import org.junit.Test;

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

public class MapTest {

    @Test
    public void test1() {
        HashMap map = new HashMap();
        HashMap map2 = new HashMap();
        map2.put("map1","str");
        map2.put("map29","9999list");
        map.put("key1", "value1");
        map.put("key2", null);
        //value不为空的情况下，key不能为空
        map.put(null, "value3");
        map.put(null, null);
        map.put("key4", "value4");
        //不可添加重复的key
        map.put("key1", "123");
        //批量
        map.putAll(map2);
        System.out.println(map);

        System.out.println("------------------------");
        Object key2 = map.remove("key2");
        System.out.println(key2);
        System.out.println(map);

        System.out.println("------------------------");
        System.out.println(map.get("key1"));
        System.out.println(map.size());
        System.out.println(map.containsKey("key2"));
        System.out.println(map.containsValue("value4"));

        System.out.println("------------------------");
        Set set = map.keySet();
        for(Object key: set) {
            System.out.println("key：" + key + "，value：" + map.get(key));
        }

        Collection values = map.values();
        for(Object value: values) {
            System.out.println(value);
        }

        System.out.println("------------------------");
        Set entrySet = map.entrySet();
        for (Object entry : entrySet) {
            System.out.println(entry);
        }
    }
}
